package jp.ac.aiit.spg.entity;

import java.io.Serializable;
import java.util.*;

import javax.persistence.*;

@Entity
public class SpgWBS implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// version ***********************************
	@Version
	private Integer version;

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// id ***********************************
	@Id
	@GeneratedValue
	private Integer id;

	public Integer getId() {
		return this.id;
	}
	
	// プロジェクト（１つ）***********************
	@OneToOne
	private SpgProject project;

	public SpgProject getProject() {
		return project;
	}

	public void setProject(SpgProject project) {
		this.project = project;
	}

	// タスク（複数） ***********************
	
	// eager fetch 指定 このエラー対策：failed to lazily initialize a collection of role: ee.chura.entity.SpgWBS.tasks, no session or session was closed
	// 変更バージョン。コレクションをSetに戻す。順序づけをする。
	@OneToMany(mappedBy="wbs", fetch = FetchType.EAGER)
	@OrderBy("wbsNumber ASC")
	private Set<SpgTask> tasks = new HashSet<SpgTask>();

	
	public Set<SpgTask> getTasks(){
		return this.tasks;
	}

	public void setTasks(Set<SpgTask> tasks) {
		this.tasks = tasks;
	}
	
	public void addTask(SpgTask st) {
		this.tasks.add(st);
	}
		
	
	public void removeTask(SpgTask st) {
		this.tasks.remove(st);
	}


	
	
}
